﻿using IBLL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace _2022_2_28.Controllers
{
    public class LogInController : Controller
    {
        private IStudentsBll _bll;
        public LogInController(IStudentsBll bll)
        {
            _bll = bll;
        }
        [HttpGet]
        public IActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public async Task<IActionResult> Index(string account,string password,string identity) 
        {
            if (identity.Equals("1"))
            {
                var data = await _bll.SignlnAsyc(account, password);
                if (data == null)
                {
                    return RedirectToAction("Index");
                }
                else
                {
                    HttpContext.Session.SetString("key", data.Id.ToString());
                    return Redirect("../StudentArea/WelecomeStudent/Index");
                }
            }
            else 
            {
                return View();
            }
        }
    }
}
